package routers

import (
	"net/http"

	"github.com/gin-gonic/gin"

	"db2_ddl_search/controllers"

	"time"
)

//初始化路由
func InitWebRouter() *gin.Engine {

	router := gin.Default()
	//心跳
	router.GET("/health", func(context *gin.Context) {
		context.String(http.StatusOK, "ok")
	})

	router.LoadHTMLFiles("./static/main.html")
	//前端页面
	router.GET("/", func(context *gin.Context) {
		context.HTML(http.StatusOK, "main.html", gin.H{"t": time.Now().Unix()})
	})
	router.StaticFS("/dist", http.Dir("./static/dist"))

	//树节点
	router.POST("/base/catalog/child", controllers.GetTreeChild)
	//获取对象
	router.POST("/base/db/objects/get/:scema/:type/:objectname", controllers.GetDbObject)
	//搜索对象
	router.POST("/base/db/objects/query", controllers.SearchDbObjects)
	
	//刷新索引
	router.GET("/base/db/objects/refreshindex", controllers.SaveEsIndex)

	return router
}
